//
//  UIButton+Extension.swift
//  ShangHaiWeiBo
//
//  Created by 蔡杰 on 16/2/26.
//  Copyright © 2016年 蔡杰. All rights reserved.
//

import UIKit

extension UIButton {


    convenience init(buttonName:String, buttonColor:UIColor = UIColor.grayColor(), fontSize:CGFloat = 17, backImageName: String?=nil, imageName:String?=nil){
    
    
        self.init()
        setTitle(buttonName, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(buttonColor, forState: .Normal)
        if let imageName = imageName{
        
            setImage(UIImage(named: imageName), forState: .Normal)
            setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        }
        if let backImageName = backImageName {
        
            setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
        
    }
}
